package com.rongji.dfish.demo.base;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.rongji.dfish.base.Utils;
import com.rongji.dfish.demo.entity.PubLoginUser;
import com.rongji.dfish.demo.pub.service.UserService;
import com.rongji.dfish.framework.FrameworkHelper;
import com.rongji.dfish.framework.controller.BaseController;
import com.rongji.dfish.ui.command.AlertCommand;
import com.rongji.dfish.ui.command.DialogCommand;

public class DemoBaseController extends BaseController {
	@Autowired
	private UserService userService;
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public PubLoginUser getLoginUser(HttpServletRequest request) {
		String loginUserId = FrameworkHelper.getLoginUser(request);
		PubLoginUser loginUser = null;
		if (Utils.notEmpty(loginUserId)) {
			loginUser = userService.get(loginUserId);
		}
//		if (loginUser == null) {
//			loginUser = UserService.getGuestUser();
//		}
		return loginUser;
	}

	@Override
    protected AlertCommand buildWarnAlert(String alertMsg) {
	    return super.buildWarnAlert(alertMsg).setCover(true);
    }

	@Override
    protected DialogCommand buildErrorDialog(Throwable t) {
	    return super.buildErrorDialog(t).setCover(true);
    }

}
